﻿// <copyright file="TimesPeopleActivities.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-05-07</date>
// <summary>TimesPeopleActivites class definition</summary>

namespace NYTimes
{
    using System;
    using System.Collections.ObjectModel;
    using NYTimes.Core;
    using NYTimes.Data;

    /// <summary>
    /// New York Times TimesPeople Activities API
    /// </summary>
    /// <remarks>
    /// activities for a specific user.  For more information, see 
    /// <a href="http://developer.nytimes.com/docs/timespeople_api">this article</a>.
    /// </remarks>
    public class TimesPeopleActivities : TimesPeople
    {
        /// <summary>
        /// Initializes a new instance of the TimesPeopleActivities class.
        /// </summary>
        public TimesPeopleActivities()
        {
            this.Activities = new ObservableCollection<Activity>();

            if (SampleData.IsInDesignTool)
            {
                var xml = SampleData.GetSampleData("Activities.xml");

                this.Parse(xml);
            }
        }

        /// <summary>
        /// Gets the "activities" data type
        /// </summary>
        public override string DataType
        {
            get { return "activities"; }
        }

        /// <summary>
        /// Gets an observable collection of <see cref="NYTimes.Data.Activity"/> objects.
        /// </summary>
        public ObservableCollection<Activity> Activities { get; private set; }

        /// <summary>
        /// Parse the result set
        /// </summary>
        /// <param name="resultSet">the XML result set</param>
        public override void ParseResultSet(System.Xml.Linq.XElement resultSet)
        {
            ParseActivities(resultSet, this.Activities);
        }

        /// <summary>
        /// Clear the activity list
        /// </summary>
        /// <param name="failure">the web client exception</param>
        public override void OnException(Exception failure)
        {
            this.Activities.Clear();
        }
    }
}
